package org.ainlolcat.ainscience.column;

import org.ainlolcat.ainscience.entity.Entity;
import org.ainlolcat.ainscience.matrix.MatrixFileParser;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

/**
 * @author ainlolcat
 * Date: 12/21/11
 */
public abstract class CustomColumn extends AbstractColumn {

    public abstract Column generateColumn(Hashtable<String,String> params, Entity entity);

    //add value operation
    public void addValues(List values){throw  new UnsupportedOperationException("Custom column does not supports external value modification");}
    public void addValue(String value){throw  new UnsupportedOperationException("Custom column does not supports external value modification");}

    //set value operation
    public void setValues(List values){throw  new UnsupportedOperationException("Custom column does not supports external value modification");}
    public boolean setValueAt(int rowNum, Object value){throw  new UnsupportedOperationException("Custom column does not supports external value modification");}

    //remove value operation
    public boolean removeAt(int num){ return false;}
    public void removeLast(){}

    public Column clone(){
        String clonename = null;
        String cloneaxis = null;
        Integer clonetype = null;

        if (getName()!=null){
            clonename = getName();
        }
        if (getAxis()!=null){
            cloneaxis = getAxis();
        }
        if (getType()!=null){
            clonetype = getType();
        } else {
            clonetype =  MatrixFileParser.MATRIX_DELIMETER_TYPE_STRING;
        }

        List clonevalues = new ArrayList();
        for (int i=0;i<size();i++){
            if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_DOUBLE)){
                clonevalues.add(new Double((Double)getValue(i)));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_INTEGER)){
                clonevalues.add(new Integer((Integer)getValue(i)));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_STRING)){
                clonevalues.add(new String((String)getValue(i)));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_BOOLEAN)){
                clonevalues.add(new Boolean((Boolean)getValue(i)));
            }
        }

        Column clone = new ColumnImpl(clonevalues);
        if (clonename!=null) clone.setName(clonename);
        if (cloneaxis!=null) clone.setAxis(cloneaxis);
        if (clonetype!=null) clone.setType(clonetype);
        return clone;
    }

}
